package com.wms.shop.controller;

import com.wms.common.core.utils.SecurityUtils;
import com.wms.common.core.web.controller.BaseController;
import com.wms.common.core.web.domain.AjaxResult;
import com.wms.shop.domain.Address;
import com.wms.shop.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 客户地址Controller
 *
 * @author zzm
 * @date 2021-12-19
 */
@RestController
@RequestMapping("/wx/address")
public class WxAddressController extends BaseController
{
    @Autowired
    private IAddressService addressService;

    /**
     * 查询客户地址列表
     */
    @GetMapping("/list")
    public AjaxResult list(Address address)
    {
        address.setUserId(SecurityUtils.getUserId());
        List<Address> list = addressService.selectAddressList(address);
        return AjaxResult.success(list);
    }


    /**
     * 获取客户地址详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(addressService.selectAddressById(id));
    }

    /**
     * 新增客户地址
     */
    @PostMapping(value = "save")
    public AjaxResult add(@RequestBody Address address)
    {
        address.setUserId(SecurityUtils.getUserId());
        return toAjax(addressService.insertAddress(address));
    }

    /**
     * 修改客户地址
     */
    @PostMapping(value = "update")
    public AjaxResult edit(@RequestBody Address address)
    {
        return toAjax(addressService.updateAddress(address));
    }

    /**
     * 删除客户地址
     */
    @DeleteMapping(value = "delete/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(addressService.deleteAddressById(id));
    }
}
